package dict.agency;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import utils.MailUtil;

public class McpDict {

	public static Map<String, String> STATE = new HashMap<String, String>();
	public static Map<String, String> RISK = new HashMap<String, String>();
	public static Map<String, Long> ALERT = new HashMap<String, Long>();
	public static Map<String, Long> HIDE = new HashMap<String, Long>();

	static {

		STATE.put("000", "Congratulations ,transaction successful");
		STATE.put("001", "Processing");
		STATE.put("002", "Failure");
		STATE.put("101", "Parameters missing or invalid");
		STATE.put("102", "Unsupported request type");
		STATE.put("104", "Invalid base amount");
		STATE.put("105", "Unsupported card currency");
		STATE.put("106", "Service not available");
		STATE.put("107", "Unsupported base currency");
		STATE.put("108", "Invalid Merchant number");
		STATE.put("110", "Invalid IPAddress");
		STATE.put("111", "Invalid Transaction.");
		STATE.put("112", "Invalid Money.");
		STATE.put("113", "Invalid Card Number.");
		STATE.put("114", "Invalid Format.");
		STATE.put("115", "No such issuers.");
		STATE.put("116", "Invalid Batch Number.");
		STATE.put("117", "Invalid Terminal Number.");
		STATE.put("118", "Invalid Password.");
		STATE.put("119", "Invalid Original Amount.");
		STATE.put("120", "Less than the book balance.");
		STATE.put("121", "Duplicate Transaction.");
		STATE.put("122", "Error Processing.");
		STATE.put("123", "Merchant is not registered.");
		STATE.put("124", "Confiscation of cards.");
		STATE.put("125", "No such issuers.");
		STATE.put("126", "Payment Request Already Sent.");
		STATE.put("127", "No Action Taken.");
		STATE.put("128", "No Such Authorization Transaction.");
		STATE.put("129", "Error contaction Service Gateway.");
		STATE.put("130", "Card Expired.");
		STATE.put("131", "Failure Card.");
		STATE.put("132", "Uneven settlement approved the sending started.");
		STATE.put("133", "SW could not get reply from IS.");
		STATE.put("134", "Invalid Password.");
		STATE.put("135", "Transaction not allowed for Card.");
		STATE.put("136", "Invalid Original Amount.");
		STATE.put("137", "Number of Withdrawals Exceeded.");
		STATE.put("138", "PIN Retries exceeded.");
		STATE.put("139", "Invalid Operator Number.");
		STATE.put("140", "Uneven settlement.");
		STATE.put("141", "Does not match the certificate number.");
		STATE.put("142", "Invalid Batch Number.");
		STATE.put("143", "Invalid Terminal Number.");
		STATE.put("144", "Invalid Parameters");
		STATE.put("145", "Error Occurred While Converting Message");
		STATE.put("146", "Invalid Request parameters");
		STATE.put("147", "Error Occurred While verifying Signature");
		STATE.put("148", "Error occurred While Signing");
		STATE.put("149", "Failed to Sign Message");
		STATE.put("150", "Parameter Type Not Matches");
		STATE.put("151", "Invalid Payment Method");
		STATE.put("152", "The Merchant doesn't have privilege of connect to institute directly");
		STATE.put("153", "Configure error of direct connection");
		STATE.put("154", "The institute of direct connection has not been activated");
		STATE.put("155", "Invalid Parameter Length");
		STATE.put("156", "Invalid password of the current institute");
		STATE.put("157", "Charset Not Supported");
		STATE.put("158", "Charset Can Not Be Empty");
		STATE.put("159", "Language Not Supported");
		STATE.put("160", "Language Can Not Be Empty");
		STATE.put("161", "Sign Method Not Supported");
		STATE.put("162", "Sign Method Can Not Be Empty");
		STATE.put("163", "orgcode is Empty or Not Supported");
		STATE.put("164", "The orgcode of local payment is not supported");
		STATE.put("165", "The orgcode of international credit card payment is not supported");
		STATE.put("166", "Invalid order amount format");
		STATE.put("167", "Invalid Email Format");
		STATE.put("168", "Invalid IP address");
		STATE.put("169", "Invalid Billing");
		STATE.put("170", "Invalid Shipping ");
		STATE.put("171", "Invalid Date Format");
		STATE.put("172", "The length of date is larger than 14");
		STATE.put("173", "Date of the order cannot be empty");
		STATE.put("174", "Gateway order id cannot be empty");
		STATE.put("175", "Rate service call exception");
		STATE.put("176", "Real exchange rate is empty");
		STATE.put("177", "Session has expired");
		STATE.put("178", "Browser cookie is blocked");
		STATE.put("179", "Black list filter");
		STATE.put("180", "Hit card-number black list");
		STATE.put("181", "Hit email black list");
		STATE.put("182", "Hit IP black list");
		STATE.put("183", "Hit address black list");
		STATE.put("184", "merchant order number incorrect");
		STATE.put("185", "Transaction is abnormal");
		STATE.put("186", "Unsupported Gateway Version");
		STATE.put("187", "Duplicate Order Number Detected");
		STATE.put("188", "Duplicate Order Number with Different Payment URL");
		STATE.put("189", "Duplicate Order Number with Different Amount and Currency.");
		STATE.put("190", "Order has already been paid and cannot re-submit");
		STATE.put("191", "Your order has been processed successfully and currently under review status. Please do not re-submit this order to avoid repeated deduction.");
		STATE.put("192", "The order has being processed");
		STATE.put("193", "Merchant Not Exists");
		STATE.put("194", "Error Occurred  While Notifying the Merchant");
		STATE.put("195", "Invalid Order Amount");
		STATE.put("196", "Currency Not Matches");
		STATE.put("197", "Target institute error");
		STATE.put("198", "Initiator of the refund must be specified");
		STATE.put("199", "Acquiring refund order id cannot be empty");
		STATE.put("200", "Merchant is not available");
		STATE.put("201", "Refund amount must be specified");
		STATE.put("202", "Refund id must be specified");
		STATE.put("203", "Gateway order id must be specified");
		STATE.put("204", "Currency wallet of the account has not been activated");
		STATE.put("205", "deposit to this account has been disabled");
		STATE.put("206", "withdraw from this account has been disabled");
		STATE.put("207", "This merchant acquiring channel no available");
		STATE.put("208", "Not enough balance");
		STATE.put("209", "The order status is error");
		STATE.put("210", "Refund is not allowed for an order which already has a chargeback");
		STATE.put("211", "Duplicate refund order number");
		STATE.put("212", "This institute doesn't support refund");
		STATE.put("213", "This institution prohibited to do refund");
		STATE.put("214", "The current transaction is out of the range of refund");
		STATE.put("215", "The transaction is currently not refundable");
		STATE.put("216", "Status code error");
		STATE.put("217", "Connection refused");
		STATE.put("218", "The request timeout");
		STATE.put("219", "Payment abnormal");
		STATE.put("220", "Available refund amount is not enough");
		STATE.put("221", "The order does not exist.");
		STATE.put("222", "The order has already been paid");
		STATE.put("223", "The order has been closed");
		STATE.put("224", "Invalid order amount");
		STATE.put("225", "withdraw from this account has been disabled");
		STATE.put("226", "deposit to this account has been disabled");
		STATE.put("227", "The Original Payment Order Number Does not Exist");
		STATE.put("228", "Duplicated Payment Request");
		STATE.put("229", "Acquiring Institute Error");
		STATE.put("230", "Payment Amount Not Matches");
		STATE.put("231", "Unknown Payment Status");
		STATE.put("232", "Information of the payment instruction does not exist");
		STATE.put("233", "Refund amount is larger than payment amount");
		STATE.put("234", "Payment at institute side is invalid");
		STATE.put("235", "The currency is not supported");
		STATE.put("236", "Payment URL and merchant URL are not matched");
		STATE.put("237", "Some order number you supplied are not matched");
		STATE.put("238", "The order has been done");
		STATE.put("239", "Information of the remittance is not unique");
		STATE.put("240", "Service type is temporary not support");
		STATE.put("241", "The remittance's amount you typed is less than the order's amount");
		STATE.put("242", "Currency of remittance is different from order's");
		STATE.put("243", "The order is auditing and could not be changed");
		STATE.put("244", "Institute order does not exist");
		STATE.put("245", "Institutions do not exist refund orders");
		STATE.put("246", "Channels resulting state is empty");
		STATE.put("247", "Exception notification Merchant");
		STATE.put("248", "Please check the refund amount");
		STATE.put("249", "Please contact administrator");
		STATE.put("250", "Do not duplicate payments.");
		STATE.put("251", "Insufficient funds in the account.");
		STATE.put("252", "Unable to Verify PIN");
		STATE.put("253", "Security Policy Violation");
		STATE.put("254", "Exceed Times Limitation");
		STATE.put("255", "High risk transaction");
		STATE.put("256", "Invalid Institute Parameter");
		STATE.put("257", "Invalid Transaction");
		STATE.put("258", "Exceed amount limit");
		STATE.put("259", "Restricted Card");
		STATE.put("260", "Transaction Timeout");
		STATE.put("261", "Invalid Expiration");
		STATE.put("262", "The card type is not accepted by the payment processor");
		STATE.put("263", "Do not honor");
		STATE.put("264", "Invalid Card Information");
		STATE.put("265", "Expired card");
		STATE.put("266", "Invalid account");
		STATE.put("267", "Invalid Card Verification Value (CVV)");
		STATE.put("268", "The transaction has already been settled or reversed.");
		STATE.put("269", "Exceeds PIN Retry");
		STATE.put("270", "The merchant reference code for this authorization request matches the merchant reference code of another authorization request that you sent within the past 15minutes");
		STATE.put("271", "The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the Address Verification System (AVS)check");
		STATE.put("272", "The issuing bank has questions about the request. You do not receive an authorization code programmatically");
		STATE.put("273", "Refer to card issuer");
		STATE.put("274", "Inactive card or card not authorized for card-not-present transactions");
		STATE.put("275", "The request is missing one or more required fields");
		STATE.put("276", "Only a partial amount was approved.");
		STATE.put("277", "Stolen or lost card.");
		STATE.put("278", "The customer matched an entry on the processor\u2019s negative file.");
		STATE.put("279", "The authorization has already been reversed");
		STATE.put("280", "The authorization has already been captured");
		STATE.put("281", "stand-alone credits are not allowed");
		STATE.put("282", "Redirect URL issued");
		STATE.put("283", "The transaction has been cancelled by the customer");
		STATE.put("284", "Phone Authorize");
		STATE.put("285", "Batch Send");
		STATE.put("286", "Invalid card number");
		STATE.put("287", "High Risk-Transnational transaction");
		STATE.put("288", "High Risk-Linked to high risk country");
		STATE.put("289", "High Risk-Same identity with multiple cards");
		STATE.put("290", "High Risk-Frequent transactions");
		STATE.put("291", "High Risk-Other aggregate risk");
		STATE.put("292", "Institute Transaction Timeout");
		STATE.put("293", "Settled error");
		STATE.put("294", "Failed to create settlement stream");
		STATE.put("295", "Institute settlement is failed");
		STATE.put("296", "Institute is abnormal");
		STATE.put("297", "Service of the institute is temporarily stopped");
		STATE.put("298", "Status of the institute is abnormal");
		STATE.put("299", "Merchant number does not exist in institution");
		STATE.put("300", "Invalid signature at institute side");
		STATE.put("301", "Failed to receive notification from institute");
		STATE.put("302", "Failed to connect to institute");
		STATE.put("303", "Unknown error from institute");
		STATE.put("304", "Institute is abnormal");
		STATE.put("305", "The notification's amount from institute does not match");
		STATE.put("306", "Unsupported service of the institute");
		STATE.put("307", "Real paid amount is less than order's");
		STATE.put("308", "Real refund amount is more than order's");
		STATE.put("309", "Offline remittance is abnormal");
		STATE.put("310", "The order is auditing");
		STATE.put("311", "Real paid currency is different from order's");
		STATE.put("312", "Real paid amount is less than order's");
		STATE.put("313", "Gateway order does not exist");
		STATE.put("314", "Gateway order has already been held on");
		STATE.put("315", "Gateway order has been wholly refunded");
		STATE.put("316", "Transaction has been settled");
		STATE.put("317", "Unfinished transaction");
		STATE.put("318", "Gateway order has not been held on");
		STATE.put("319", "Settle data does not exist");
		STATE.put("320", "PE losses are fail");
		STATE.put("321", "PE release fails");
		STATE.put("322", "This channel does not support reconciliation losses are linked");
		STATE.put("323", "System is maintaining");
		STATE.put("324", "HTTP request timeout");
		STATE.put("325", "Unknown exception");
		STATE.put("326", "MQ is abnormal");
		STATE.put("327", "MQ Error");
		STATE.put("328", "Message format is not available");
		STATE.put("329", "Service is offline");
		STATE.put("330", "System runtime exception");
		STATE.put("331", "This merchant acquiring channel no available");
		STATE.put("332", "Refused The Site");
		STATE.put("741", "Original Transaction does not exist");
		STATE.put("742", "Original Transaction Amount Information is not matched");
		STATE.put("743", "Not Authorization Transaction");
		STATE.put("744", "Not Acquiring Transaction");
		STATE.put("745", "Partial Refund is not permitted to Refund Transaction");
		STATE.put("746", "Exceed Partial Refund Amount");
		STATE.put("900", "Refused Transaction.");
		STATE.put("901", "Database Error.");
		STATE.put("902", "VAN auth failed");
		STATE.put("910", "Risk Card number");
		STATE.put("911", "Merchant exceed 1time limit approved");
		STATE.put("912", "Merchant exceed one day limit approved");
		STATE.put("913", "Merchant exceed one month limit approved");
		STATE.put("914", "Incorrect Merchant number");
		STATE.put("915", "Live status is not a Merchant contract. ");
		STATE.put("917", "Original transaction does not exist. ");
		STATE.put("918", "Internet access is limited to the payment. Please contact your administrator. ");
		STATE.put("920", "Card limit exceeded");
		STATE.put("921", "Insufficient funds");
		STATE.put("922", "Incorrect cardholder name");
		STATE.put("923", "Incorrect card number");
		STATE.put("924", "Incorrect expiry date");
		STATE.put("925", "Incorrect security code");
		STATE.put("926", "System Error");
		STATE.put("927", "Auth Declined");
		STATE.put("928", "The card type is not processed by the authorization center");
		STATE.put("929", "Stolen card");
		STATE.put("931", "Please contact your card issuer.");
		STATE.put("932", "Please enter the cvv no(3 digits) which is stated on the back of your credit card. ");
		STATE.put("933", "Invalid Card Type");
		STATE.put("934", "Card Type Not Supported");
		STATE.put("935", "South Korea issued cards are not available.");
		STATE.put("936", "KRW Currency cannot be accepted.");
		STATE.put("941", "Transaction has already been canceled.");
		STATE.put("942", "No transactions available for acquiring.");
		STATE.put("943", "Transaction has already been acquired.");
		STATE.put("951", "Invalid RateID");
		STATE.put("952", "Invalid ConversionRate");
		STATE.put("953", "Invalid TransactionCurrency");
		STATE.put("954", "Invalid TransactionAmount");
		STATE.put("999", "System no Kown Error");
		STATE.put("C01", "Error Merchant MD5 Sign ");
		STATE.put("C02", "Failed to Verify Signature");
		STATE.put("R01", "Merchants available balance is insufficient!");

		RISK.put("929", "929");

		ALERT.put("555", 0L);
		ALERT.put("254", 0L);
		ALERT.put("258", 0L);

		// HIDE.put("9905", 0);
	}

	public static synchronized String message(String code) {
		if (STATE.containsKey(code)) {
			return STATE.get(code).toString();
		}
		return "unknown exception";
	}

	public static synchronized void warning(String code, int limit) {
		String name = "MCP";
		String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
		if (ALERT.containsKey(code)) {
			ALERT.put(code, ALERT.get(code) + 1);
			if (new Integer(ALERT.get(code).toString()) > limit) {
				ALERT.put(code, 0L);
				MailUtil.sendEmail(MailUtil.tos, "警告", "[" + time + "]" + name + "返回码[" + code + "]超过[" + limit + "]次");
			}
		}
	}

}
